package com.salon.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.salon.common.http.response.PageResult;
import com.salon.common.utils.Query;
import com.salon.modules.sys.entity.SysLogEntity;
import com.salon.modules.sys.mapper.SysLogMapper;
import com.salon.modules.sys.service.ISysLogService;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

@Service("sysLogService")
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLogEntity>
        implements ISysLogService {

    @Override
    public PageResult<SysLogEntity> listByPage(Map<String, Object> params) {
        IPage<SysLogEntity> pageParams = new Query<SysLogEntity>().getPage(params);
        String key = (String) params.get("key");
        LambdaQueryWrapper<SysLogEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(key), SysLogEntity::getUsername, key);
        queryWrapper.orderByDesc(SysLogEntity::getCreateDate);
        IPage<SysLogEntity> page = this.page(pageParams, queryWrapper);
        List<SysLogEntity> resultList = page.getRecords();
        return new PageResult<>(page.getTotal(), page.getCurrent(), page.getSize(), resultList);
    }

}
